package club.emergency.wechat.dictionary.search.consumer.controller;

import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.utils.JsonConvert;
import club.emergency.wechat.dictionary.search.consumer.service.DictionarySearchConsumer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jifujun
 * @since 2018-11-26
 */
@Api("字典表操作接口")
@RestController
@RequestMapping("/dictionary-search")
public class DictionarySearchController {

    private DictionarySearchConsumer dictionarySearchConsumer;

    public DictionarySearchController(DictionarySearchConsumer dictionarySearchConsumer) {
        this.dictionarySearchConsumer = dictionarySearchConsumer;
    }

    @ApiOperation("查询父子点数据")
    @PostMapping("/flipListForParent")
    public ResponseEntity flipListForParent() {
        return new JsonConvert<ResponseEntity>().jsonDecode(dictionarySearchConsumer.flipListForParent(), ResponseEntity.class);
    }

    @ApiOperation("根据keyName查询子字典数据（一般在具体业务中调用）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyName", value = "关键字", required = true, dataType = "string", paramType = "query")
    })
    @PostMapping("/flipListByKeyName")
    public ResponseEntity flipListByKeyName(
            @RequestParam("keyName") String keyName
    ) {
        return new JsonConvert<ResponseEntity>().jsonDecode(dictionarySearchConsumer.flipListByKeyName(keyName), ResponseEntity.class);
    }

}
